<template>
<view>
<!--pages/topicality/xiaofeiquan/xiaofeiquan.wxml-->
<!--<import src="../../webview/contact.wxml"></import>-->
<!-- <template is="inContact" data="{{showtk}}" /> -->
<view>
  <!--  -->
  <image src="http://imgbdb3.bendibao.com/xcx/20205/20/2020520140003_96198.jpg" class="main-img">
    <view class="city-box">
      <text>{{city}}</text>
      <!-- <image src="/images/dwicon.png"></image> -->
    </view>
    <view class="change-city">
      <text style="margin-left: 70rpx;">切换城市:</text>
      <picker @change="bindProv" :value="pindex" :range="provPick">
        <view class="sel-city">
          <view class="picker">
            <text>{{provPick[pindex]}}</text>
          </view>
          <image src="/static/images/dwicon.png"></image>
        </view>
      </picker>
      <picker @change="bindCity" :value="cindex" :range="cityPick">
        <view class="sel-city">
          <view class="picker">
            <text>{{cityPick[cindex]}}</text>
          </view>
          <image src="/static/images/dwicon.png"></image>
        </view>
      </picker>
    </view>
  </image>

  <view class="nrbox">
    <view class="swiper-box" v-if="funcData!=''">
      <swiper :indicator-dots="indicatorDots" indicator-active-color="#515151" indicator-color="#ababab" :autoplay="autoplay" :interval="interval" :duration="duration">
        <block v-for="(func, index) in funcData" :key="index">
          <swiper-item>
            <view class="bmBtn-box">
              <view v-for="(item, index2) in func" :key="index2" class="bmBtn" :data-title="item.title" :data-id="item.id" :data-type="item.type" :data-url="item.url" @tap="funcBtn">{{item.title}}</view>
            </view>
          </swiper-item>
        </block>
      </swiper>
    </view>
    <view class="border-box" v-if="wzzData.guankong!=''">
      <view class="jwtitle">管控政策</view>
      <view v-for="(item, index) in wzzData.guankong" :key="index" :class="showMore1?'jw-list1':'jw-list2'" @tap="contDetail" :data-title="item.title" :data-id="item.id" :data-type="item.type" :data-url="item.url">
        <view class="jwlist-title">
          <image src="http://imgbdb3.bendibao.com/whbdb/20202/28/20200228092343_12218.png?1"></image>
          <text>{{item.title}}</text>
        </view>
        <view class="jwlist-detail" v-if="item.daoyu">{{item.daoyu}}</view>
      </view>
       <!-- 查看更多 -->
      <view class="see-more" v-if="wzzData.guankong.length>2 && showMore1" @tap="seemoreBtn" data-flag="1">
        <view>查看更多</view>
      </view>
    </view>
    <view class="border-box" v-if="wzzData.bingli!=''">
      <view class="jwtitle">病例轨迹</view>
      <view v-for="(item, index) in wzzData.bingli" :key="index" :class="showMore?'jw-list1':'jw-list2'" @tap="contDetail" :data-title="item.title" :data-id="item.id" :data-type="item.type" :data-url="item.url">
        <view class="jwlist-title">
          <image src="http://imgbdb3.bendibao.com/whbdb/20202/28/20200228092343_12218.png?1"></image>
          <text>{{item.title}}</text>
        </view>
        <view class="jwlist-detail" v-if="item.daoyu">{{item.daoyu}}</view>
      </view>
      <!-- 查看更多 -->
      <view class="see-more" v-if="wzzData.bingli.length>2 && showMore" @tap="seemoreBtn" data-flag="2">
        <view>查看更多</view>
      </view>
    </view>
    <view class="border-box" v-if="wzzData.changjian!=''">
      <view class="jwtitle">常见问题</view>
      <view v-for="(item, index) in wzzData.changjian" :key="index" :class="showMore2?'jw-list1':'jw-list2'" @tap="contDetail" :data-title="item.title" :data-id="item.id" :data-type="item.type" :data-url="item.url">
        <view class="jwlist-title">
          <image src="http://imgbdb3.bendibao.com/whbdb/20202/28/20200228092343_12218.png?1"></image>
          <text>{{item.title}}</text>
        </view>
        <view class="jwlist-detail" v-if="item.daoyu">{{item.daoyu}}</view>
      </view>
      <!-- 查看更多 -->
      <view class="see-more" v-if="wzzData.changjian.length>2 && showMore2" @tap="seemoreBtn" data-flag="3">
        <view>查看更多</view>
      </view>
    </view>
  </view>

  <!-- 导粉 -->
  <view class="daofen" v-if="infoData.daofen">
    <rich-text :nodes="infoData.daofen.content" style="user-select:text;-webkit-user-select:text">
    </rich-text>
  </view>

</view>
<!-- 快捷导航 -->
<fastnav :qrcodeimg="qrcodeimg" :citycode="citycode" :showNav="showNav" :showShare="showShare"></fastnav>
</view>
</template>

<script>
// pages/topicality/xiaofeiquan/xiaofeiquan.js
//获取应用实例
const app = getApp();
const util = require("../../../utils/util.js");
var QQMapWX = require("../../../utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.min.js");
var qqmapsdk = new QQMapWX({
  key: 'KR7BZ-XSQ3P-VGFD7-LNRZL-E7PXE-STF76'
});
import fastnav from "../../../component/fastnav/fastnav";

export default {
  data() {
    return {
      citycode: "sz",
      city: '深圳',
      province: '广东',
      pindex: 0,
      cindex: 0,
      cityPick: ["选择城市"],
      showtk: false,
      showNav: true,
      // 快捷导航是否展开
      indicatorDots: true,
      autoplay: true,
      interval: 5000,
      duration: 500,
      showMore: false,
      showMore1: false,
      showMore2: false,
      showShare: true // 显示分享按钮
      ,
      provPick: [],
      funcData: "",
      qrcodeimg: "",
      cityArray: "",
      citylist: "",
      infoData: "",
      wzzData: ""
    };
  },

  components: {
    fastnav
  },
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    util.getUrl(app.globalData.url).then(res => {
      this.getProvinceData(options.city);
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: this.infoData ? this.infoData.title : "无症状感染查询"
    };
  },
  // 分享朋友圈
  onShareTimeline: function () {
    return {
      title: this.infoData ? this.infoData.title : "无症状感染查询",
      imageUrl: "http://imgbdb3.bendibao.com/xcx/20205/20/2020520140003_96198.jpg",
      query: {
        city: this.citycode
      }
    };
  },
  methods: {
    // 获取定位
    getLocation() {
      qqmapsdk.reverseGeocoder({
        success: res => {
          let city = res.result.address_component.city; // let city="芜湖市";

          let citydata = this.citylist.filter(v => {
            if (city.indexOf(v.cityname) != -1) {
              return v;
            }
          });

          if (citydata != '' && city.indexOf(this.city) == -1) {
            uni.showModal({
              content: '您当前定位城市为' + city + '\n是否需要切换到' + city + '无症状感染查询？',
              success: res => {
                if (res.confirm) {
                  this.setData({
                    city: Array.isArray(citydata) ? citydata[0].cityname : this.city,
                    citycode: Array.isArray(citydata) ? citydata[0].citycode : this.citycode,
                    province: Array.isArray(citydata) ? citydata[0].province : this.province,
                    cityPick: ["选择城市"]
                  });
                  let clist = [];
                  this.provPick.forEach((v, k) => {
                    if (v == this.province) {
                      this.setData({
                        pindex: k
                      });
                    }
                  });
                  this.cityArray[this.pindex].citylist.forEach(v => {
                    clist.push(v.cityname);
                  });
                  this.setData({
                    cityPick: this.cityPick.concat(clist)
                  });
                  this.cityPick.forEach((v, k) => {
                    if (v == this.city) {
                      this.setData({
                        cindex: k
                      });
                    }
                  }); // 获取城市公众号二维码

                  this.getQrcode(this.citycode);
                  this.getInfoData(this.citycode);
                }
              }
            });
          }
        }
      });
    },

    // 获取城市公众号二维码
    getQrcode(citycode) {
      util.cityConfig(citycode).then(res => {
        this.setData({
          qrcodeimg: res.qrcode
        });
      });
    },

    // 获取城市
    getProvinceData(optcode) {
      let data = {
        action: "wuzhengzhuang",
        type: "city"
      };
      util.request('zhuanti.php', data).then(res => {
        this.setData({
          cityArray: res.data.data.city
        });
        let provPick = [];
        let citylist = [];
        let clist = [];
        this.cityArray.forEach(v => {
          v.citylist.forEach(v => {
            citylist.push(v);
          });
          provPick.push(v.province);
          this.setData({
            provPick,
            citylist
          });
        });

        if (this.citylist) {
          this.citylist.forEach((v, k) => {
            if (optcode == v.citycode) {
              this.setData({
                citycode: v.citycode,
                city: v.cityname,
                province: v.province
              });
            } else {
              this.setData({
                citycode: this.citycode,
                city: this.city,
                province: this.province
              });
            }
          });
        }

        this.provPick.forEach((v, k) => {
          if (v == this.province) {
            this.setData({
              pindex: k
            });
          }
        });
        this.cityArray[this.pindex].citylist.forEach(v => {
          clist.push(v.cityname);
        });
        this.setData({
          cityPick: this.cityPick.concat(clist)
        });
        this.cityPick.forEach((v, k) => {
          if (v == this.city) {
            this.setData({
              cindex: k
            });
          }
        });
        this.getInfoData(); // 获取城市公众号二维码

        this.getQrcode(this.citycode);

        if (this.citylist != "" && Array.isArray(this.citylist)) {
          // 获取定位
          this.getLocation();
        }
      });
    },

    getInfoData(citycode) {
      let data = {
        action: "wuzhengzhuang",
        citycode: citycode ? citycode : this.citycode
      };
      util.request('zhuanti.php', data).then(res => {
        if (res.data.data.daofen) {
          res.data.data.daofen.content = res.data.data.daofen.content.replace(/<p([\s\w"=\/\.:;]+)((?:(="[^"]+")))/ig, '<p').replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p').replace(/<p([\s\w"=\/\.:;]+)((?:(class="[^"]+")))/ig, '<p').replace(/<p>/ig, '<p class="p_class">').replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1').replace(/<img/gi, '<img style="width:100%;height:auto"'); // .replace(/<span>/ig, '<p class="p_class">')
        }

        uni.setNavigationBarTitle({
          title: res.data.data ? res.data.data.title : "无症状感染"
        });
        let wzzData = res.data.data.wzz; // 处理便民功能数据，每四个重新分为一组

        let funcData = [];

        if (wzzData.bianmin != '') {
          let proportion = 4; //按照比例切割

          let num = 0;

          for (let i = 0; i < wzzData.bianmin.length; i++) {
            if (i % proportion == 0 && i != 0) {
              funcData.push(wzzData.bianmin.slice(num, i));
              num = i;
            }

            if (i + 1 == wzzData.bianmin.length) {
              funcData.push(wzzData.bianmin.slice(num, i + 1));
            }
          }
        }

        if (wzzData.guankong != '') {
          if (wzzData.guankong.length > 2) {
            this.setData({
              showMore1: true
            });
          }
        }

        if (wzzData.bingli != '') {
          if (wzzData.bingli.length > 2) {
            this.setData({
              showMore: true
            });
          }
        }

        if (wzzData.changjian != '') {
          if (wzzData.changjian.length > 2) {
            this.setData({
              showMore2: true
            });
          }
        }

        this.setData({
          infoData: res.data.data,
          funcData,
          wzzData
        });
      });
    },

    // 省份选择
    bindProv: function (e) {
      this.setData({
        pindex: e.detail.value,
        cindex: 0,
        cityPick: ["选择城市"]
      });
      let clist = [];
      this.cityArray[this.pindex].citylist.forEach(v => {
        clist.push(v.cityname);
      });
      this.setData({
        cityPick: this.cityPick.concat(clist)
      });
    },

    // 城市选择
    bindCity(e) {
      this.setData({
        cindex: e.detail.value
      });
      let cityname = this.cityPick[this.cindex];
      this.citylist.forEach(v => {
        if (v.cityname == cityname) {
          let citycode = v.citycode;
          this.setData({
            citycode,
            city: cityname
          });
        }
      }); // 获取城市公众号二维码

      this.getQrcode(this.citycode);
      this.getInfoData(this.citycode);
    },

    // 便民功能点击事件
    funcBtn(e) {
      let title = e.currentTarget.dataset.title;
      let id = e.currentTarget.dataset.id;
      let type = e.currentTarget.dataset.type;
      let url = e.currentTarget.dataset.url;

      if (id != 0) {
        uni.navigateTo({
          url: '/pages/article/detail/detail?id=' + id + '&type=' + type + '&city=' + this.citycode
        });
      } else {
        this.setData({
          showtk: true
        });
        util.navContact(title, url);
      }
    },

    // 内容详情
    contDetail(e) {
      let title = e.currentTarget.dataset.title;
      let id = e.currentTarget.dataset.id;
      let type = e.currentTarget.dataset.type;
      let url = e.currentTarget.dataset.url;

      if (id != 0) {
        uni.navigateTo({
          url: '/pages/article/detail/detail?id=' + id + '&type=' + type + '&city=' + this.citycode
        });
      }
    },

    // 进入客服会话
    contact() {
      this.setData({
        showtk: false
      });
    },

    // 关闭
    close() {
      this.setData({
        showtk: false
      });
    },

    // 查看更多
    seemoreBtn(e) {
      let flag = e.currentTarget.dataset.flag;

      if (flag == 1) {
        this.setData({
          showMore1: false
        });
      } else if (flag == 2) {
        this.setData({
          showMore: false
        });
      } else if (flag == 3) {
        this.setData({
          showMore2: false
        });
      }
    },

    /**
     * 页面滑动事件的处理函数
     */
    onPageScroll: function (e) {
      this.setData({
        showNav: false
      });
    }
  }
};
</script>
<style>
/* pages/topicality/xiaofeiquan/xiaofeiquan.wxss */
.main-img{width: 100%;height: 276rpx;}
.city-box{background: #ffffff;border-radius: 35rpx;padding: 10rpx 30rpx;position: absolute;
top: 40rpx;right: 30rpx;display: flex;align-items: center;}
.city-box text{font-size: 30rpx;font-weight: bolder;}
.city-box image{width: 23rpx;height: 15rpx;margin-left: 10rpx;}
.change-city{background:rgba(255,255,255,1);box-shadow:0rpx 6rpx 6rpx rgba(0,0,0,0.16);
opacity:1;border-radius:20rpx;padding:30rpx 0rpx;position: absolute;top:235rpx;width: 90%;
margin-left: 36rpx;display: flex;align-items: center;}
.change-city text{font-size:28rpx;font-family:PingFang SC;font-weight:bold;line-height:36rpx;
color:rgba(20,20,20,1);opacity:1;width: 102rpx;text-align: center;white-space:nowrap;}
.sel-city{display: flex;align-items: center;margin-left: 80rpx;}
.sel-city image{width: 19rpx;height: 10rpx;margin-left: 15rpx}

.nrbox{margin-top: 80rpx; }
.swiper-box{padding: 30rpx 36rpx 0 36rpx;border-bottom: 15rpx solid #EEEEEE;}
swiper{height: 260rpx;}
.bmBtn-box{display: flex;flex-direction: row;align-items: center;flex-wrap: wrap;}
.bmBtn{background-color:#eee;color:#717171;font-size: 30rpx;border-radius:43rpx;text-align: center;
padding: 20rpx 10rpx;width: 252rpx;margin: 0 10rpx 30rpx 40rpx;}
.border-box{border-bottom: 15rpx solid #EEEEEE;padding: 30rpx 0rpx;}
.border-box:last-child{border: 0}
/* 内容 */
.jwtitle{font-size:32rpx;font-family:PingFang SC;font-weight:600;line-height:44rpx;
color:rgba(20,20,20,1);opacity:1;padding: 0 36rpx}
.jw-list{border-top:15rpx solid #EEEEEE;padding: 30rpx 30rpx 30rpx 45rpx;}
.jwlist-title{display: flex;flex-direction: row;align-items: center;}
.jwlist-title image{width: 24rpx;height: 16rpx;}
.jwlist-title text{font-size:28rpx;font-family:PingFang SC;font-weight:600;line-height:40rpx;
color:rgba(20,20,20,1);opacity:1;margin-left: 20rpx;}
.jwlist-detail{font-size:28rpx;font-family:PingFang SC;font-weight:500;line-height:40rpx;
color:rgba(154,154,154,1);opacity:1;margin-top: 20rpx;margin-left: 42rpx;}
.jw-title1{font-size:32rpx;font-family:PingFang SC;font-weight:600;line-height:44rpx;
color:rgba(20,20,20,1);opacity:1;padding: 30rpx 0 0rpx 45rpx;border-top:15rpx solid #EEEEEE; }
.jw-list1{border-bottom:1rpx solid #EEEEEE;padding: 30rpx 30rpx 30rpx 45rpx;}
.jw-list1:last-child{border: 0}
.jw-list1:nth-of-type(n+4){display:none;}
.jw-list2{border-bottom:1rpx solid #EEEEEE;padding: 30rpx 30rpx 30rpx 45rpx;}
.jw-list2:last-child{border: 0}

/* 查看更多 */
.see-more{display: flex;justify-content: center;margin: 30rpx 0;}
.see-more view{background-color: #EEEEEE;padding: 20rpx 40rpx;font-size:26rpx;border-radius:12rpx;
font-family:PingFang SC;font-weight:600;color: #141414;text-align: center;width: 200rpx;white-space:nowrap;}
/* 导粉 */
.daofen{margin:0 30rpx 80rpx 30rpx;text-align: center;}
.p_class{margin:10rpx 30rpx;line-height: 50rpx;}

</style>